<?php 
if(KT!='KhiThe') exit;
class newComments_controller extends newComments_model{
		
	public function __construct(){
		global $lang;
		$this->lang = $lang;
		parent::__construct();
		parent::addObject('khithe_template');
		parent::addObject('khithe_paging');
		parent::addObject('khithe_request');
		parent::addObject('khithe_string');
	}
	
	public function index_action()
	{
		$resultHtml = '';
		$limit=25;
		$totalRows = mysql_num_rows(parent::getcomments('',''));
		$strPaging = $this->display_paging($totalRows, intval($this->valUrl(1)), intval($limit), url_base.'admin/newComments/index', $this->lang,'/');
		$this->lang['paging'] = $strPaging;
		$strHtmlContent = $this->khithe_display('index');
		$this->arrBlockHtml = $this->khithe_getBlockHtml($strHtmlContent);
		
		$resultcomment = parent::getcomments(intval($this->valUrl(1)), intval($limit));
		while( $row_comments = mysql_fetch_assoc($resultcomment) )
		{
			$arrcomment = array(
				"page"=>$this->valUrl(1),
				"cell_ID"=>$row_comments['ID'],
				"cell_1"=>'<input name="delId[]" type="checkbox" value="'.$row_comments['ID'].'" />',
				"cell_2"=>$row_comments['FullName'],
				"cell_3"=>$row_comments['YahooChat'].'@yahoo.com',
				"cell_4"=>$this->cutString($row_comments['Content'],45),
				"cell_5"=>$row_comments['PostDate']!=''?date("d-m-Y",$row_comments['PostDate']):'',
				"cell_6"=>$row_comments['Status']!='true'?$this->lang['enabled']:$this->lang['disabled'],
				"class_cell"=>$row_comments['Status']=='false'?"cell_groupitem1":"cell_groupitem_ex1",
				
			);
			$resultHtml .= $this->khithe_assign($this->arrBlockHtml['comments'],$arrcomment);
			
		} mysql_free_result($resultcomment);
		
		$strHtmlContent = $this->khithe_assignBlock($strHtmlContent, array('htmlCat'=>$resultHtml));
		$strHtmlContent = $this->khithe_assign($strHtmlContent, $this->lang);
		
		return $strHtmlContent;
	}
	
	public function detail_action()
	{
		if($_GET['iframe']=='true')
		{
			$resultcomment = parent::getcommentID($this->valUrl(1));
			$row_comments = mysql_fetch_assoc($resultcomment);
			$strHtmlContent = $this->khithe_display('detail');
			$this->lang['titlePageEditor'] = isset($this->lang['editTitle'])?$this->lang['editTitle']:NULL;
			$this->lang['page'] = $this->valUrl(2);
			$this->lang['commentID'] = $row_comments['ID'];
			$this->lang['Content'] = $row_comments['Content'];
			$this->lang['PostDate'] = $row_comments['PostDate']!=''?date('d-m-Y',$row_comments['PostDate']):'';
			$this->lang['Fullname'] = $row_comments['FullName'];
			$this->lang['YahooChat'] = $row_comments['YahooChat'];
			
			$strHtmlContent = $this->khithe_assign($strHtmlContent, $this->lang);
			return $strHtmlContent;
		}
	}
	
	public function index_ajax_action()
	{
		switch ($this->valUrl(2))
		{
			case 'close':
				$arr = explode(',',$this->valUrl(3));
				foreach ( $arr as $ID ){
					$select = parent::getcommentID($ID);
					while($row = mysql_fetch_assoc($select)){
						if($row['Status']=='false'){
							$done = parent::setCheckedcomment($ID,'true');
						}
					}
				}
			break;
			
			case 'open':
				$arr = explode(',',$this->valUrl(3));
				foreach ( $arr as $ID ){
					$select = parent::getcommentID($ID);
					while($row = mysql_fetch_assoc($select)){
						if($row['Status']=='true'){
							$done = parent::setCheckedcomment($ID,'false');
						}
					}
				}
			break;
			
			case 'del':
				$arr = explode(',',$this->valUrl(3));
				foreach ( $arr as $ID ){
					$done = parent::delCheckedcomment($ID);	
				}
			break;
		}
		if($this->valUrl(2)!="" && isset($done)){
			return $this->index_action();
			
		}else{
			return 'notOK';
		}	
	}


}
?>